<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML XMLNS="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1" />

<% 
if request.QueryString("FromDispatch")<>"yes" then
	if request.Cookies("Hsuser")="" then
	%>
		<SCRIPT type="text/javascript">
		parent.parent.window.location.href="LoginScreen.asp";
		</SCRIPT>
	<%
	end if
end if 

'-----checking to see what the COD settings are-------- 
set fs=server.CreateObject("scripting.filesystemobject")
filepath=server.MapPath("access/backend/CODs.txt")
			  
if not fs.fileexists(filepath) then
	fs.createtextfile(filepath)
end if
			
set f=fs.opentextfile(filepath)
			
if not f.AtEndOfStream then
	CODs=f.readline
else
	CODs="no"
end if

f.close
set f=nothing
set fs=nothing
%>	

<TITLE>Customer Information</TITLE>
<LINK HREF="UniversalStyleSheet.css" REL="stylesheet" TYPE="text/css" />
<STYLE TYPE="text/css">
<!--
body {
	margin-left: 1px;
	margin-top: 1px;
	margin-right: 1px;
	margin-bottom: 1px;
}
-->
</STYLE>

<SCRIPT type="text/javascript">

function fnMadeChanges(what)
    {
	var mc=document.getElementById("MadeChanges");
	mcv=mc.value;
	mcv=mcv + what + "\n";
	mc.value=mcv;
	document.getElementById("savemsg").innertext="Changes Need Saved";
	}



function BtnSaveClick()
    {
    var fn=document.getElementById("FirstName");
    var ln=document.getElementById("LastName");
    var ad=document.getElementById("Address");
    var c=document.getElementById("City");
    var s=document.getElementById("State");
    var z=document.getElementById("Zip");

    Fname=fn.value;
    Lname=ln.value;
    Addr=ad.value;
    Cty=c.value;
    St=s.value;
    Zipcode=z.value;
    msg="";

    if (Fname==""){msg=msg + "- First Name\n";} 

    if (Lname==""){msg=msg + "- Last Name\n";}

    if (Addr==""){msg=msg + "- Address\n";}

    if (Cty==""){msg=msg + "- City\n";}

    if (St==""){msg=msg + "- State\n";}

    if (Zipcode==""){msg=msg + "- Zip Code\n";}


    if (msg != ""){
	    alert( "Cant Save Changes. The Following Required Fields Were Blank:\n\n" + msg);
	    return;
        }

    <% if request.QueryString("FromDispatch")="yes" then %>
    document.FrmCustInfo.action="SaveAccount.asp?FromDispatch=yes";
    <% end if %>
    document.FrmCustInfo.onsubmit ="";
    document.FrmCustInfo.submit();
    }
</SCRIPT>
</HEAD>

<BODY>

<TABLE WIDTH="500" HEIGHT="100" BORDER="0" ALIGN="left" CELLPADDING="0" CELLSPACING="0">
   <TR>
    <TD WIDTH="325" ALIGN="center" VALIGN="top">
	<FORM ACTION="SaveAccount.asp" METHOD="post" NAME="FrmCustInfo" ID="FrmCustInfo" onSubmit="javascript: return false;">
	<TABLE WIDTH="440" HEIGHT="200" BORDER="0" ALIGN="left" CELLPADDING="0" CELLSPACING="0">
	 <TR>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperLeft.png"></TD>
        <TD WIDTH="400" HEIGHT="20" BACKGROUND="Images/TableUpperMiddle.png"></TD>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperRight.png"></TD>
      </TR>
      <TR>
        <TD WIDTH="20" HEIGHT="159" BACKGROUND="Images/TableMiddleLeft.png"></TD>
        <TD WIDTH="400" BGCOLOR="#FFFFFF">
		
          <TABLE WIDTH="400" HEIGHT="145" BORDER="0" CELLPADDING="0" CELLSPACING="1" BORDERCOLOR="#FFFFFF" ID="CustInfo">
            <TR>
              <TD HEIGHT="22" ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><SPAN CLASS="SearchFormText">Account <BR>
              Number: </SPAN></TD>
              <TD VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><INPUT NAME="AccountNumber" TYPE="text" ID="AccountNumber" SIZE="15" disabled="disabled" /></TD>
              <TD ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><LABEL><SPAN CLASS="SearchFormText">Contract ID:
                  </SPAN></LABEL></TD>
              <TD VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><INPUT NAME="Contract_ID_Display" TYPE="text" ID="Contract_ID_Display" SIZE="15" disabled="disabled"/>
                <INPUT NAME="Contract_ID" TYPE="hidden" ID="Contract_ID" /></TD>
            </TR>
            <TR>
              <TD WIDTH="91" HEIGHT="22" ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><P><SPAN CLASS="SearchFormText">First<BR>
              Name:</SPAN>
                <LABEL></LABEL>
              </P>
              </TD>
              <TD WIDTH="114" HEIGHT="22" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><INPUT NAME="FirstName" TYPE="text" ID="FirstName" TABINDEX="1" onChange="fnMadeChanges('First Name')" SIZE="15" MAXLENGTH="30"/>
              </TD>
              <TD WIDTH="78" ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><SPAN CLASS="SearchFormText">Last<BR>
              Name:</SPAN>
             <LABEL></LABEL></TD>
              <TD WIDTH="127" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><INPUT NAME="LastName" TYPE="text" ID="LastName" TABINDEX="2" onChange="fnMadeChanges('Last Name')" SIZE="15" MAXLENGTH="50"/>
              </TD>
            </TR>
            <TR>
              <TD HEIGHT="22" ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2"><SPAN CLASS="SearchFormText">Address:</SPAN>
                <LABEL></LABEL></TD>
             <TD HEIGHT="22" COLSPAN="3" VALIGN="top" BGCOLOR="#D2FFD2"><INPUT NAME="Address" TYPE="text" ID="Address" TABINDEX="3" onChange="fnMadeChanges('Address')" SIZE="40" MAXLENGTH="100"/>
               <INPUT NAME="MadeChanges" TYPE="hidden" ID="MadeChanges">
              </TD>
           </TR>
            <TR>
              <TD HEIGHT="22" ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2">			  </TD>
              <TD HEIGHT="22" COLSPAN="3" VALIGN="top" BGCOLOR="#D2FFD2"><INPUT NAME="City" TYPE="text" ID="City" TABINDEX="4" onChange="fnMadeChanges('City')" SIZE="20" MAXLENGTH="50"/>
                <INPUT NAME="State" TYPE="text" ID="State" TABINDEX="5" onChange="fnMadeChanges('State')" SIZE="5" MAXLENGTH="2"/>
                <INPUT NAME="Zip" TYPE="text" ID="Zip" TABINDEX="6" onChange="fnMadeChanges('Zip Code')" SIZE="5" MAXLENGTH="10"/>
              </TD>
           </TR>
            <TR>
              <TD HEIGHT="22" ALIGN="right" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><SPAN CLASS="SearchFormText">Phone:</SPAN>
                <LABEL></LABEL></TD>
              <TD HEIGHT="22" COLSPAN="3" VALIGN="top" BGCOLOR="#D2FFD2" CLASS="TableTitles"><INPUT NAME="Phone" TYPE="text" ID="Phone" TABINDEX="7" onChange="fnMadeChanges('Phone Number')" MAXLENGTH="25"/>
              </TD>
           </TR>
            <TR>
              <TD HEIGHT="33" COLSPAN="4" ALIGN="right" VALIGN="top" BGCOLOR="#FFFFFF" CLASS="style5">
			  <SPAN ID="savemsg" STYLE="font-style:italic; color:#990000; display:block; text-align:right" CLASS="TableTitles"></SPAN>
			 <% if (request.QueryString("FromDispatch")<>"yes") and (CODs="yes") then %>
			  <A HREF="customerinformation.asp"><IMG SRC="Images/NewCustomerButton.png" ALT="New Customer" WIDTH="60" HEIGHT="30" BORDER="0" /></A>
			  <% end if %>
                 
			  <A HREF="javascript:BtnSaveClick()"><IMG SRC="Images/SaveButton.png" ALT="Save" WIDTH="60" HEIGHT="30" BORDER="0" /></A>
			 
				 
				 <% if request.QueryString("FromDispatch")<>"yes" then %>          
				 <A HREF="javascript:NewTicketClick()"><IMG SRC="Images/NewTicketButton.png" ALT="New Ticket" WIDTH="60" HEIGHT="30" BORDER="0" /></A>
				 <% end if %>				 
				 </TD>
            </TR>
       </TABLE>        
	  </TD>
        <TD WIDTH="20" BACKGROUND="Images/TableMiddleRight.png"></TD>
      </TR>
      <TR>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerLeft.png"></TD>
        <TD WIDTH="400" HEIGHT="20" BACKGROUND="Images/TableLowerMiddle.png"></TD>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerRight.png"></TD>
      </TR>
    </TABLE>
	</FORM>	</TD>
    <TD WIDTH="225" ALIGN="center" VALIGN="top">
	<% 
ContractID=request.QueryString("ContractID")
if ContractID <> "" then
	if isnumeric(left(contractid,1)) then
		table="customers"
		database="homesmart_customers.mdb"
	else
		table="non_homesmart_customers"
		database="tickets.mdb"
	end if
	
	dim rs,ra,db,db2,rs2,ra2
	set db=server.CreateObject("adodb.connection")
	set db2=server.CreateObject("adodb.connection")
	set rs=server.CreateObject("adodb.recordset")
	set rs2=server.CreateObject("adodb.recordset")
	FilePath=server.MapPath("/afterhours/access/backend/" & database)
	FilePath2=server.MapPath("/afterhours/access/backend/homesmart_customers.mdb")

	db.open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filepath
	sql="select * from " & table & " where contract_ID='" & ContractID & "';"
	sql2="select appliance_name from appliances where contract_ID='" & ContractID & "';" 
	rs.open sql,db
	if database="tickets.mdb" then
		db2.open "provider=Microsoft.Jet.oledb.4.0;data source=" & filepath2
		rs2.open sql2,db2,1,2
	else
		rs2.open sql2,db,1,2
	end if
	
	ra=rs.getrows()
	rs.close

	if not rs2.eof then
		ra2=rs2.getrows()
		rs2.close
		x=0
		AppStr=""
		mbAppStr=""
		
		do until x>ubound(ra2,2)
			AppStr=AppStr & x+1 & ") &nbsp; &nbsp; " & ra2(0,x) & "</br>"
			mbAppStr=mbAppStr & ra2(0,x) & "|"
			x=x+1
		loop
		mbAppStr=left(mbAppStr,len(mbAppStr)-1)
	else
		if table="customers" then
			AppStr="(ERROR retrieving this HomeSmart customers appliances:  Contract_ID not matched.)"
		else 
			AppStr="(Non-HomeSmart)"
		end if
	end if

	db.close 
	set db=nothing
	set db2=nothing
	set rs=nothing
	set rs2=nothing
	%>
	<SCRIPT type="text/javascript" LANGUAGE="javascript">
		document.title="<%= trim(ra(2,0)) & " " & trim(ra(3,0)) %>"
		document.getElementById("AccountNumber").value="<%= trim(ra(0,0)) %>"
		document.getElementById("Contract_ID").value="<%= trim(ra(1,0)) %>"
		document.getElementById("Contract_ID_Display").value="<%= trim(ra(1,0)) %>"
		document.getElementById("FirstName").value="<%= trim(ra(2,0)) %>"
		document.getElementById("LastName").value="<%= trim(ra(3,0)) %>"
		document.getElementById("Address").value="<%= trim(ra(4,0)) %>"
		document.getElementById("City").value="<%= trim(ra(5,0)) %>"
		document.getElementById("State").value="<%= trim(ra(6,0)) %>"
		document.getElementById("Zip").value="<%= trim(ra(7,0)) %>"
		document.getElementById("Phone").value="<%= trim(ra(8,0)) %>"
		<% if request.QueryString("FromDispatch")<>"yes" then %>
		parent.parent.HistoryFrame.location="TicketHistory.asp?Contract_ID=<%= ra(1,0) %>"
		<% end if %>
	</SCRIPT>
	<%
end if
%>
	<TABLE WIDTH="290" BORDER="0" ALIGN="left" CELLPADDING="0" CELLSPACING="0">
	  <TR> 
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperLeft.png"></TD>
        <TD WIDTH="250" HEIGHT="20" BACKGROUND="Images/TableUpperMiddle.png"></TD>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperRight.png"></TD>
      </TR>
      <TR>
        <TD WIDTH="20" BACKGROUND="Images/TableMiddleLeft.png"></TD>
        <TD BGCOLOR="#FFFFFF" CLASS="Appliances">
		
	  <% 'middle cell of appliances table
			if ContractID<>"" then
				response.Write(AppStr)
			else
				response.Write("&nbsp;")
			end if
		%>		</TD>
        <TD WIDTH="20" BACKGROUND="Images/TableMiddleRight.png"></TD>
      </TR>
      <TR>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerLeft.png"></TD>
        <TD WIDTH="250" HEIGHT="20" BACKGROUND="Images/TableLowerMiddle.png"></TD>
        <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerRight.png"></TD>
      </TR>
    </TABLE></TD>
  </TR>
</TABLE>

<SCRIPT type="text/javascript">
function NewTicketClick()
    {

    var mc=document.getElementById("MadeChanges")
    var mcv=mc.value;
    var mbAppStr="<%= mbAppStr %>";
    var apparray=mbAppStr.split("|");
    var appstr="";

    for (x=0;x <= apparray.length; x++){
	    appstr += apparray[x] + "\n"
    }

    if (mcv != ""){
	    if (confirm ("You've made changes to the following element(s) of this account:" & vbcrlf & "_____________________ \n\n" + mcv + "_____________________\n\n" + "- Click 'OK' if you would like to save changes now and then click 'New Ticket' again after saving. \n\n- Click 'Cancel' if you would not like to save the changes you've made to this account and proceed with starting a new ticket.")){
		    BtnSaveClick();
		    return;
	    }
    }

    var CODs="<%= CODs %>";

    var cid=document.getElementById("Contract_ID");

    if (cid.value == "") {
	    if (CODs == "no") {
		    msg= "You cannot start a new ticket until you have a customer to associate the ticket with.\nSo if this is a HomeSmart customer then return to the 'Search' page to find and open this customers HomeSmart account.\n\nIf this is NOT a HomeSmart customer then you will need to explain to this customer that HomeSmart is not currently accepting calls for non-HomeSmart covered repairs.";
	        }
	    else{
		    msg= "You cannot start a new ticket until you have a customer to associate the ticket with.\nSo either pull up a customers account first or if you are entering new customer information\nthen you must save that information first so that the new customer has a Contract_ID \nfor the new ticket to be associated with.";
    	
	    }
	    alert (msg);
	    return;
    }

    if (isNaN(cid.value.substring(0,1))) {
	    if (CODs == "no") {
		    msg=" *THIS CUSTOMER IS A NON-HOMESMART CUSTOMER*\n\nCurrently, HomeSmart is not accepting repair calls for non-HomeSmart covered appliances outside of business hours.\nYou will need to inform this customer that HomeSmart is not able to accept this call at this time.";
		    alert (msg);
		    return;
		    }
	    else{
		    alert ("*THIS CUSTOMER IS A NON-HOMESMART CUSTOMER*\n\nRemember to remind them:\n - They will be paying a trip fee, possibly at 1.5 times the normal rate which will be quoted by the technician.\n - They will be responsible for paying for parts and labor quoted by the technician due at the time of service.");
	    }
	    var nonhs=1;
    }

    if (nonhs != 1){
	    if (confirm ("Is this ticket for one of this customers covered appliances?\n\n OK=Yes\nCancel=No") == false) {
		    if (CODs == "no") {
			    alert( "This is a non-HomeSmart covered appliance.\n\nCurrently, HomeSmart is only accepting calls for HomeSmart-covered appliances.\nYou will need to inform this customer that HomeSmart cannot accept a non-covered appliance repair call outside of standard business hours and that they will need to call HomeSmart during business hours the next business day because you are only taking calls for covered appliances.");
			    return;
			}
		    else{
			    alert( "*THIS IS A NON-HOMESMART COVERED REPAIR*\n\nRemember to remind them:\n - They will be paying a trip fee, possibly at 1.5 times the normal rate which will be quoted by the technician.\n - They will be responsible for paying for parts and labor quoted by the technician due at the time of service.");
    		
		    }
	    }
    }

    parent.TicketFrame.location="TicketWindow.asp?Contract_ID=" + cid.value;
	
    }
</SCRIPT>

</BODY>
</HTML>
